var mineData=[]
var myMineData = []

function initSelect(){
    $("[name='mineAreaId']").empty();
    $("[name='mineId']").empty();
    $("[name='mineAreaId']").append(new Option('请选择矿区',''));
    $("[name='mineId']").append(new Option('请选择矿井',''));
    for (let i = 0; i < mineData.length; i++) {
        $("[name='mineAreaId']").append(new Option(mineData[i].name, mineData[i].id));
    }
    form.render("select");
}
function initMySelect(){
    $("[name='mineAreaId']").empty();
    for (let i = 0; i < myMineData.length; i++) {
        $("[name='mineAreaId']").append(new Option(myMineData[i].name, myMineData[i].id));
    }
    form.render("select");
}


function getMineData(){
    postAjaxNoSuccessTip('/api/mine/getAllMineListBySelect',null,function (response){
        mineData=response.data;
        initSelect();
    },null);
}

function getMyMineData(){
    postAjaxNoSuccessTip('/api/analyse/getMineList',null,function (response){
        myMineData=response.data;
        initMySelect();
    },null);
}
/**
 * 选择下拉
 */
function handleChange(e1,e2){
    $("#"+e2).empty();
    $("#"+e2).append(new Option('请选择矿井',''));
    let checkValue=$("#"+e1).val();
    if($("#"+e1).get(0).selectedIndex===0){
        form.render("select");
        return;
    }
    let mine= mineData.filter(x=>x.id==checkValue)[0]
    for (let i = 0; i < mine.children.length; i++) {
        $("#"+e2).append(new Option(mine.children[i].name, mine.children[i].id));
    }
    form.render("select");
}


function loadByMineId(mineId,e1,e2){
    postAjaxNoSuccessTip('/api/mine/getAllMineListBySelect',null,function (response){
        mineData=response.data;
        initSelect();
        for (let i = 0; i < mineData.length; i++) {
            const element = mineData[i];
            for (let j = 0; j < element.children.length; j++) {
                const mine = element.children[j];
                if(mine.id==mineId){
                    //开始加载
                    $('#'+e1).val(element.id)
                    handleChange(e1,e2);
                    $('#'+e2).val(mineId)
                    form.render("select");
                    break;
                }
            }
        }
    },null);
}